/**
 * Copyright (C) 2015-2018 IQIYI
 * All rights reserved.
 *
 * Author     : 王海斌
 * E-mail     : wanghaibin@qiyi.com
 * Version    :
 * Date       : Fri 20 Nov 2020 10:19:05 AM CST
 * Destription: 测试菱形纯虚继承
 */

#include <stdio.h>

class base
{
public:
    base () {}
    virtual ~base () {}

    // 纯虚函数
    virtual void vfun() {
        printf("call base\n");
    };
};

class child_a : public virtual base
{
public:
    child_a (){}
    virtual ~child_a (){}

    virtual void vfun() {
        printf("call child_a \n");
    }
};

class child_b : public virtual base
{
public:
    child_b () {}
    virtual ~child_b () {}

    virtual void vfun() {
        printf("call child_b \n");
    }
private:
    /* data */
};

class grandson_d : public child_a, public child_b
{
public:
    grandson_d () {}
    virtual ~grandson_d () {}
    virtual void vfun() {  // 如果不提供此虚函数的重载则编译器会直接报错
        printf("call grandson_d \n");
    }
};

int main(int , char *[])
{
    grandson_d test;
    test.vfun();
    printf("sizeof(base)=%d, sizeof(child_a)=%d, sizof(grandson_d)=%d\n",
            sizeof(base), sizeof(child_a), sizeof(grandson_d));
    return 0;
}
